package 自己写一个json解析器测试;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class JsonObject extends HashMap<String,Object> {

    @Override
    public Object put(String key, Object value) {
        return super.put(key, value);
    }

    @Override
    public Object get(Object key) {
        return super.get(key);
    }

    public List<Entry<String, Object>> getAllKeyValue() {
        return new ArrayList<Entry<String, Object>>(super.entrySet());
    }

    public JsonObject getJsonObject(String key) {
        if (!super.containsKey(key)) {
            throw new IllegalArgumentException("Invalid key");
        }

        Object obj = get(key);

        if (obj instanceof JsonObject) {
            return (JsonObject) obj;
        }

        return null;
    }

    public JsonArray getJsonArray(String key) {
        if (!super.containsKey(key)) {
            throw new IllegalArgumentException("Invalid key");
        }

        Object obj = get(key);
        if (obj instanceof JsonArray) {
            return (JsonArray) obj;
        }

        return null;
    }
}